/**
 * Created by Delicate on 2017/5/31.
 */

$(document).ready(function(){
	init();
    monitor();
    service();
    onEnterKeyListener();
});

function init(){
    if(top != self){
        top.location.href = location.href;
    }
}
function monitor(){

}
function service(){

}

function onEnterKeyListener(){//监听Enter事件
$("#loginForm").keydown(function(e){
	 var e = e || event,
	 keycode = e.which || e.keyCode;
	 if (keycode==13) {
	  $(".u-btn").trigger("click");
	 }
	});
}

function test1(){}

function submitForm(obj){
	var username = $("#mobile").val().trim();
    var password = $("#password").val().trim();
    // const returnUrl = $(obj).data("url");
    if (!$valid.phone(username)) {
        return layer.msg("请输入11位合法用户名!");
    }
    if (!$valid.password(password)) {
        return layer.msg("请输入6-32位合法密码!");
    }
    var data = {
        mobile: username,
        password: password
    }
    $.ajax({
        url: ctx+"/login/doLogin"
        , type: "post"
        , data: data
        , dataType: "json"
        , success: function(data){
            if (data.state=="ok") {
                if (data.returnUrl.length > 0) {
                    location.href = ctx + data.returnUrl;
                } else {
                    location.href = ctx+"/platform";
                }
            } else {
                layer.alert(data.msg);
            }
        }
    })
}